package middlewares

import (
	"github.com/gin-gonic/gin"
	"go-web/utils"
	"reflect"
)

// HttpRecover http失败恢复中间件
func HttpRecover() gin.HandlerFunc {
	return func(c *gin.Context) {
		defer func() {
			err := recover()
			if err != nil {
				// 系统级报错
				utils.Json(c, utils.JsonPanicFailCode, reflect.ValueOf(err).String(), nil)
			}
		}()
		// 处理请求
		c.Next()
	}
}
